function passgarp=garpe(p,q,e)
% REQUIRES warshall
%
%GARP-website: http://www.revealedpreferences.org
%Aug 6, 2012

T=size(p,1);

DRP=eye(T);
P0=zeros(T,T);
for i=1:T
    for j=[1:i-1, i+1:T]
        if p(i,:)*e*q(i,:)'>=p(i,:)*q(j,:)'
            DRP(i,j)=1;
            if p(i,:)*q(i,:)'>p(i,:)*q(j,:)'
                P0(i,j)=1;
            end % if >
        end % if >=
    end % for j
end % for i

RP=warshall(DRP);

passgarp=1;
for i=1:T
    for j=[1:i-1, i+1:T]
        if RP(i,j) && P0(j,i) % see GARP-definition
            passgarp=0; break
        end % if
    end % for j
    if ~passgarp, break, end
end % for i
